﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace WindowsFormsApp10
{
    public partial class Form3 : Form
    {
        private SELECT select;
        private bool isDelete;
        public Action update;
        public Form3(SELECT se, bool isd)
        {
            InitializeComponent();
            select = se;
            isDelete = isd;
            if (isDelete)
            {
                label1.Text = "删除项ID：";
            }
            else
            {
                label1.Text = "查找项ID：";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int ID = int.Parse(textBox1.Text);
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=mydatabase.db;Version=3;"))
            {
                connection.Open();
                if (isDelete)
                {
                    label1.Text = "删除项ID：";
                    if (select == SELECT.Student)
                    {
                        Form1.DeleteStudentRecord(ID, connection);
                    }
                    else if (select == SELECT.Class)
                    {
                        Form1.DeleteClassRecord(ID, connection);
                    }
                    else if (select == SELECT.School)
                    {
                        Form1.DeleteSchoolRecord(ID, connection);
                    }
                    update();
                }else
                {
                    label1.Text = "查找项ID：";
                    if (select == SELECT.Student)
                    {
                        MessageBox.Show(Form1.FindStudentByID(ID,connection), "查找完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (select == SELECT.Class)
                    {
                        MessageBox.Show(Form1.FindClassByID(ID, connection), "查找完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (select == SELECT.School)
                    {
                        MessageBox.Show(Form1.FindSchoolByID(ID, connection), "查找完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                connection.Close();
            }
            
           
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
